Skip to content

LF-5211: Farm notes data model and API#4091

Draft
litefarm-pr-bot wants to merge 5 commits intointegrationfrom
LF-5211-farm-notes-data-model-and-api
Draft

LF-5211: Farm notes data model and API#4091
litefarm-pr-bot wants to merge 5 commits intointegrationfrom
LF-5211-farm-notes-data-model-and-api

Conversation

@litefarm-pr-bot
Copy link
Collaborator

@litefarm-pr-bot litefarm-pr-bot commented Mar 17, 2026

Description

LiteFarm has no first-class way for farm members to leave notes visible to the whole team on the Home dashboard. This PR adds the backend data model and REST API for the Farm Notes / Noticeboard feature, providing the foundation that frontend PRs will build on.

Two new tables are introduced: farm_note (per-farm notes with optional image attachment and an is_private flag so authors can keep notes to themselves) and farm_notes_read (a composite-PK table recording each user's last-read timestamp, enabling the unread indicator badge). Four CRUD permissions are seeded (IDs 188–191, get/add/edit/delete:farm_notes) and assigned to all active roles.

Controllers enforce authorship: PATCH and DELETE require user_id to match the note's author, returning 403 otherwise. GET filters results so private notes are only returned to their author. Image uploads are compressed via imaginaryPost and stored in S3. All new routes go through the standard checkScope + hasFarmAccess middleware chain; farm_note_id is registered in entitiesGetters so cross-farm access is blocked by the existing ACL infrastructure.

Jira link: https://lite-farm.atlassian.net/browse/LF-5211

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

20 integration tests added covering all four CRUD endpoints plus the read-tracking endpoints:

  • farmNote.test.js (14 tests): GET visibility rules (public/private/wrong-farm), POST with and without file, PATCH author/non-author/wrong-farm, DELETE soft-delete/non-author/wrong-farm
  • farmNotesRead.test.js (6 tests): GET returns null before any mark-read, returns timestamp after, wrong-farm 403; PATCH creates row, updates timestamp, wrong-farm 403

Integration tests run against a real test DB with the new migrations applied. No frontend component in this PR — visual review not applicable. CI will run the full test suite.

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have ordered translation keys alphabetically (optional: run pnpm i18n to help with this)
  • I have added the GNU General Public License to all new files

Adds the full backend for the farm notes feature: three Knex migrations
(farm_note table, farm_notes_read table, permissions), two Objection models,
two controllers with CRUD + read-status handlers, two Express routes, server
mounts, hasFarmAccess entity getter, and integration tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@litefarm-pr-bot litefarm-pr-bot requested review from a team as code owners March 17, 2026 22:17
@litefarm-pr-bot litefarm-pr-bot requested review from Duncan-Brain and removed request for a team March 17, 2026 22:17
@kathyavini kathyavini requested review from kathyavini and removed request for Duncan-Brain March 18, 2026 16:44
};
},

editFarmNote() {
Copy link
Collaborator

@kathyavini kathyavini Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SayakaOno I saw this in the RTK Query endpoint too, but I have no idea why the file / image is excluded from the PATCH; I don't think that was part of the plan (or maybe I missed it!)

I'm double-checking with Loïc here, but I'm pretty sure anything that can be set in POST (including image) should be PATCH-able.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For image removal on the PATCH, I am planning to send data.image_url = null. Let me know if that works for you 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work, thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, I've updated the patch request body and pushed!

@SayakaOno SayakaOno marked this pull request as draft March 18, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants